﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.Common
{
    /// <summary>
    /// 登陆日志
    /// </summary>
    public class PartyUserLoginLog : EntityBase
    {
        /// <summary>
        /// SessionID
        /// </summary>
        public string SessionID { get; set; }

        /// <summary>
        /// ip地址
        /// </summary>
        public string LoginIP { get; set; }

        /// <summary>
        /// 登陆id
        /// </summary>
        public string LoginID { get; set; }

        /// <summary>
        /// 登陆时间
        /// </summary>
        public DateTime? LoginTime { get; set; }

        /// <summary>
        /// 登陆方式 
        /// </summary>
        public int Source { get; set; }

        /// <summary>
        /// 最后操作时间
        /// </summary>
        public DateTime?  LastOpTime { get; set; }

        /// <summary>
        /// 注销时间
        /// </summary>
        public DateTime? LoginOutTime { get; set; }

        /// <summary>
        /// 更新操作时间
        /// </summary>
        /// <param name="sessionId"></param>
        public static void UpdateLastOpTime(string sessionId)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "sessionId",
                    Value = sessionId
                }
            };
            string sql = @"update  tblPartyUserLoginLog set LastOpTime=now() WHERE sessionId = ?sessionId";
            MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());
            
        }
        /// <summary>
        /// 更新操作时间
        /// </summary>
        /// <param name="Id"></param>
        public static void UpdateLastOpTimeBy(string Id)
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "Id",
                    Value = Id
                }
            };
            string sql = @"update  tblPartyUserLoginLog set LastOpTime=now() WHERE Id = ?Id";
            MySqlHelper.ExecuteNonQuery(sql, parameters.ToArray());

        }
    }
}
